#ifndef JABSTRACTSOCKET_H
#define JABSTRACTSOCKET_H

#include <JXQIO/JAbstractIO>
#include <JXQNetwork/JHostAddr>

namespace JXQ
{

class JAbstractSocketPrivate;

class JXQLIB_EXPORT JAbstractSocket : public JAbstractIO
{
public:
	enum Type {
		Primordial, Tcp, Udp
	};
	~JAbstractSocket();

protected:
	explicit JAbstractSocket(Type type);

public:
	bool open(OpenMode mode) override;
	virtual bool open(int handle, OpenMode mode);
	bool close() override;

public:
	int64_t ioctl(unsigned int cmd, void * = nullptr) override;
	void flush() override;
	int64_t bytesAvailable() const override;
	int64_t size() const override;

public:
	bool bind(uint16_t port);
	Type type() const;
	JHandle handle() const;

protected:
	int64_t virtualRead(int64_t bufSize, void *buffer) override;
	int64_t virtualWrite(int64_t bufSize, const void *buffer) override;

private:
	J_DECLARE_PRIVATE(JAbstractSocket)
	J_DISABLE_COPY(JAbstractSocket)
};

} //namespace JXQ


#endif //JABSTRACTSOCKET_H
